package com.vf.admin.miaodong.controller.pay;

import com.vf.admin.common.BaseController;
import com.vf.admin.common.Constants;
import com.vf.admin.common.entity.Result;
import com.vf.admin.common.splitpage.SplitPageBean;
import com.vf.admin.miaodong.entity.WechatPayConfigs;
import com.vf.admin.miaodong.entity.WxAppidConfig;
import com.vf.admin.miaodong.service.AfterWxAppidConfigService;
import com.vf.admin.utils.StringEx;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : NemoMeng
 * @Date 2023/12/28 11:39
 */
@Controller
@RequestMapping("/after/wxAppidConfig")
public class AfterWxAppidConfigController extends BaseController {

    @Resource
    private AfterWxAppidConfigService afterWxAppidConfigService;


    @RequestMapping("/list")
    public String list(SplitPageBean splitPageBean) {

        //构建参数
        Map<String, Object> map = new HashMap<>();
        Map<Integer, String> statusMap = Constants.getstatusMap();
        List<WxAppidConfig> list = afterWxAppidConfigService.list(map, splitPage);
        request.setAttribute("list", list); //列表
        request.setAttribute("splitPage",splitPage);  //分页参数
        return this.sucess("/web/after/pay/wxAppidConfigList");
    }

    /**
     * 详情
     */
    @RequestMapping("/detail")
    public String detail(Integer id){

        WxAppidConfig wxAppidConfig = afterWxAppidConfigService.get(id);
        request.setAttribute("wxAppidConfig",wxAppidConfig);
        return this.sucess("/web/after/pay/wxAppidConfigEdit");

    }




    /**
     * 保存或是修改
     * @param params
     * @return
     */
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Result saveOrUpdate(WxAppidConfig params) {
        try {
            afterWxAppidConfigService.saveOrUpdate(params);
            return sucessJSON("成功");
        } catch (Exception e) {
            return errorJSON("系统繁忙");
        }
    }

    /**
     * 删除
     */

    @RequestMapping("/del")
    @ResponseBody
    public Result del(Integer id){
        try{
            if(StringEx.isNull(id)){
                return this.errorJSON("未获取到要删除的信息");
            }
            afterWxAppidConfigService.del(id);
            return this.sucessJSON("删除成功");
        }catch (Exception e){
            return this.errorJSON("系统繁忙");
        }
    }

}
